#include <avr/io.h>
#include <avr/delay.h>

#define F_CPU 3686400UL


//Tones
#define C 956
#define D 851
#define E 758
#define F 716
#define G 638
#define A 568
#define H 506
#define LC 478
#define DDR DDRA
#define PORT PORTA
#define toneLength 150

unsigned int enabled = 0;

// Prepare the sound port
void initSoundPort(void)
{
	DDR = 0xFF;
}
void playNote(int note){
	int i;
	for(i = 0; i < toneLength; i++) {
		PORT = PORT ^ 0x01;
		switch (note) {
			case A:
			_delay_us(A);
			PORT = PORT ^ 0x00;
			_delay_us(A);
			break;
			case F:
			_delay_us(F);
			PORT = PORT ^ 0x00;
			_delay_us(F);
			break;
		}
	}
}
void alarmOff(void){
	enabled = 0;
}
void alarmOn(void){
	enabled = 1;
	while (enabled) {
		playNote(F);
		playNote(A);
	}
}

int isEnabled(void){
	return enabled;
}